package com.xkdx.guangguang.fragment.shopinfo;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.DiscountInfo;
import com.xkdx.guangguang.shareclass.ProductInfo;

public class ShopInfoUnitModule extends AbsModule {
	public List<ProductInfo> unitInfoList;

	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;

			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getProductList")) {
					unitInfoList = parseProductInfo(jsonObj
							.getJSONObject("DetailInfo"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	private List<ProductInfo> parseProductInfo(JSONObject person)
			throws Exception {
		List<ProductInfo> list = new ArrayList<ProductInfo>();

		try {
//			JSONObject stut = (JSONObject) person.get("DetailInfo");
			if (!(person.isNull("DetailInfo"))) {
				JSONArray ListInfo = (JSONArray) person
						.getJSONArray("DetailInfo");

				for (int i = 0; i < ListInfo.length(); i++) {
					JSONObject jsonObj = ((JSONObject) ListInfo.opt(i));
					ProductInfo unitInfo = new ProductInfo();
					unitInfo.setProductID(jsonObj.getString("ID"));
					unitInfo.setProductName(jsonObj.getString("Product_Name"));
					unitInfo.setExChange_Num(jsonObj.getString("ExChange_Num"));
					unitInfo.setRemain_Num(jsonObj.getString("Remain_Num"));
					unitInfo.setLogo(jsonObj.getString("Logo"));
					unitInfo.setProductPrice(jsonObj.getString("Product_Price"));
					list.add(unitInfo);
				}
			}
		} catch (Exception e) {
			throw e;
		}

		return list;

	}

}
